let stu = require('../Dao/mongse');

//学生的业务层
module.exports = {
    //分页查询学生信息
    async getStudentInfoByPage(current, pageSize,type,value ) {
        //分页对象
        let pageBean = {};
        //获得要显示的数据
        let datas = await stu.getuser(current, pageSize,type,value );
        //获得总条数
        let total = await stu.getTolNum({[type]:value});

        //计算总页数
        let tolPage = Math.ceil(total / pageSize);
        //开始封装分页对象
        pageBean = { datas, current, pageSize, total, tolPage }
        //返回分页对象
        return pageBean;
    },


    //添加学生
    async stuAdd({ name, age, gender, address,classId }) {
        let result = await stu.insertUser({ name, age, gender, address, classId });
        return result;
    },

    //删除学生
    async stuDelete({ _id }) {
        let result = await stu.remove({ _id });
        return result;
    },

    //批量删除删除学生
    async stuRem(arr) {
        let result = await stu.deletions(arr);
        return result;
    },

    //修改学生
    async stuUpdata(stuid, stuObj) {
        let result = await stu.updateStu(stuid, stuObj);
        return result;
    },

    //查询学生详细信息
    async stuChaXiang(stuid) {
        return await stu.updateStu(stuid);
    },


    //查询学生信息
    async querys(obj) {
        //{path:'classId',match:{className:'3班'}
        if (obj.data) {
            let objCls = {};
            objCls.path = obj.data;
            objCls.match = { [obj.data]: obj.classId }
            let result = await stu.stuTypeClassId(objCls);
            return result.filter(item => item[obj.data]);
        } else {
            return await stu.stuTypes(obj);
        }

    }

}